package spring_mybatis_integration;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping
public class CustomerInfoController implements BeanFactoryAware{
	private BeanFactory beanFactory;
	
	@RequestMapping(method = RequestMethod.GET,
									value = "/customerInfoController")
	public ModelAndView processCustomerInfo(HttpServletRequest request, HttpServletResponse response)		{
		CustomerService customerService = beanFactory.getBean("customerService", CustomerService.class);
		CustomerModel customerModel = customerService.getCustomerById(Integer.parseInt(request.getParameter("id")));
//		System.out.print(customerModel);
		Map<String, Object> map = new HashMap<>();
		map.put("customer_info", customerModel);
		return new ModelAndView("customerInfoResult", map);
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		// TODO Auto-generated method stub
		this.beanFactory = beanFactory;
	}
}
